package demo009.file;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;


/***
 * Java File学习
 * @author zanglaowei
 * 2019-11-22
 */
public class FileTest {
	public static void main(String args[]){
//		TestListFile();
		
		File directory = new File("");// 参数为空
	    String courseFile;
		try {
			courseFile = directory.getCanonicalPath();
			//注意反斜杠 转义
			System.out.println(courseFile+"\\testFile");
//			courseFile=courseFile+"\testFile";
			FileKit.createDir(courseFile+"\\testFile");
			FileKit.createFile(courseFile,"123.txt");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	      
		Path path=new Path();
		
		path.getPath();
		
	}

	/**
	 * 列出文件夹下的文件或文件夹
	 */
	public static void TestListFile(){
		//创建File对象  
        File file = new File("C:\\Qt");  
        //获取该目录下的所有文件  
        String[] files = file.list();  
          
        for (String f : files){  
            System.out.println(f);  
        }  
       System.out.println("---------------------------");   
        //listFiles是获取该目录下所有文件和目录的绝对路径  
        File[] fs = file.listFiles(new FilenameFilter(){

			@Override
			public boolean accept(File dir, String name) {
				// TODO Auto-generated method stub
				return name.endsWith(".txt");
			}
        	
        });  
        for (File f : fs){  
            System.out.println(f);  
        }  
	}
	
	
}
